package com.gym.code.generator.impl.dao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.gym.code.generator.Contants;
import com.gym.code.generator.impl.AbstractFaceGenerator;
import com.gym.code.generator.model.mapping.layer.dao.IDaoLayerGenerateModel;
import com.gym.code.generator.model.mapping.method.AbstractMethodGenerateModel;
import com.gym.code.generator.model.mapping.method.MethodDeleteModel;
import com.gym.code.generator.model.mapping.method.MethodInsertModel;
import com.gym.code.generator.model.mapping.method.MethodSelectModel;
import com.gym.code.generator.model.mapping.method.MethodUpdateModel;

/**
 * 
 * @author xinchun.wang 
   @email: 532002108@qq.com
 * @createTime 2015-4-12 上午11:30:46
 */
public class DaoFaceGenerator extends AbstractFaceGenerator<IDaoLayerGenerateModel>{

    private DaoFaceGenerator(){}
	
    private static DaoFaceGenerator instance = new DaoFaceGenerator();
	
	public static DaoFaceGenerator getInstance(){
		return instance;
	}   
	
	@Override
	protected List<String> generateClassBegin(IDaoLayerGenerateModel bean) {
		List<String> result = new ArrayList<String>();
		result.add("public interface " + getIDaoName(bean) + " {");
		return result;
	}

	@Override
	protected List<String> generateFields(IDaoLayerGenerateModel bean) {
		return Collections.emptyList();
	}

	@Override
	protected List<String> generateMethods(IDaoLayerGenerateModel bean) {
		List<String> result = new ArrayList<String>();
		for(AbstractMethodGenerateModel method : bean.getMethodModelList()) {
			if(method instanceof  MethodDeleteModel){
				result.add(generateMethodDeclare(method) + ";");
			} else if(method instanceof  MethodUpdateModel){
				result.add(generateMethodDeclare(method) + ";");
			} else if(method instanceof  MethodSelectModel){
				result.add(generateSelectMethodDeclare((MethodSelectModel)method) + ";");
			} else if(method instanceof  MethodInsertModel){
				result.add(generateMethodDeclare(method) + ";");
			}
		}
		return result;
	}

	@Override
	protected String generatePackage(IDaoLayerGenerateModel bean) {
		return "package " + bean.getPackageName() + Contants.$lineSplit;
	}
	
}
